package tasks.leetcode;

public class TaskRemoveDuplicates {
    public static void main(String[] args) {
        int i = new TaskRemoveDuplicates().removeDuplicates(new int[]{1, 1, 2, 3, 4, 4, 5});
        System.out.println(i);
    }

    // 1 1 2 3 4 4 5
    public int removeDuplicates(int[] nums) {
        if(nums == null || nums.length == 0) return 0;
        // 移除重复的元素
        int slow = 1;
        int fast = 1;
        int n = nums.length;
        while (fast < n) {
            if (nums[fast] != nums[fast - 1]) {
                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }
}
